library ManaDrainAbility initializer Init requires entities, utils, SpellBar
    /*
    --------------------------------------------------------------------------
    # 魔法吸吮
    --------------------------------------------------------------------------
    */

    globals
        public integer ABILITY_ID = 'AHdr'
    endglobals

    private function Release takes Spell spell returns nothing
        call SpellBar.get(spell.m_unit).destroy()
        call spell.destroy()
    endfunction

    private function SpellFinish takes nothing returns nothing
        local Spell spell = Spell.get(SpellEvent.CastingUnit, ABILITY_ID)
        call Release(spell)
    endfunction

    private function SpellAction takes Spell spell returns nothing
    endfunction

    private function SpellChannel takes nothing returns nothing
        local Spell spell
        local SpellBar spellBar
        local integer level

        if not (IsWidgetAlive(SpellEvent.CastingUnit)) then
            return
        endif

        set spell = Spell.create(SpellEvent.CastingUnit, ABILITY_ID)

        set level = GetUnitAbilityLevel(spell.m_unit, ABILITY_ID)
        
        if level == 1 then
            set spell.m_amount = 30 //每波伤害
        elseif level == 2 then
            set spell.m_amount = 40 //每波伤害
        elseif level == 3 then
            set spell.m_amount = 50 //每波伤害
        endif

        set spell.m_timeCast = 6.0
        set spell.m_interval = 1.0 //间隔

        set spellBar = SpellBar.create(spell.m_unit)
        set spellBar.m_isReverse = true //反向
        call spellBar.start(spell.m_timeCast, -60.0)
    endfunction

    private function Init takes nothing returns nothing
        call RegisterSpellChannelResponse(ABILITY_ID, SpellChannel)
        //call RegisterSpellEffectResponse(ABILITY_ID, SpellEffect)

        call RegisterSpellEndCastResponse(ABILITY_ID, SpellFinish)
        call RegisterSpellFinishResponse(ABILITY_ID, SpellFinish)
    endfunction

endlibrary
